package org.vaadin.example.nf4v.demo;

import org.vaadin.example.nf4v.demo.ui.MainWindow;
import org.vaadin.example.nf4v.demo.ui.admin.AdminWindow;
import org.vaadin.example.nf4v.demo.ui.admin.pages.DashboardPage;
import org.vaadin.example.nf4v.demo.ui.admin.pages.UsersPage;
import org.vaadin.example.nf4v.demo.ui.main.pages.InternalPage;
import org.vaadin.example.nf4v.demo.ui.main.pages.WelcomePage;
import org.vaadin.nf4v.core.config.builder.NavigationConfigBuilder;

/**
 * Example of application navigation configuration, using navigation builder.
 */
public class DemoNavigationConfig extends NavigationConfigBuilder {

    private static DemoNavigationConfig demoNavigationConfig;

    @Override
    protected void configure() {

        // .asMainWindow() is optional, but makes declaration more explicit
        context("main").window(MainWindow.class).asMainWindow();
        // note, you can set window specific vaadin theme
        context("admin").window(AdminWindow.class).theme("runo");
        /*
          core
           /navigation
              /simple navigation
              /new tab activation              
              /cross context
              /parameters
           /uri
              /uri handling
           /handlers
              /param resolver
              /uri handler
          ext
              /beforenav
              /afternav
              /menu
              /security
          tips
              /page leave warning
         */
        inContext("main")
                .page(WelcomePage.class).asHomePage()
                // navigation options
                // context switch
                // wizard
                // new tab opening
                // params handling
                // custom param resolver
                // secured context (login demo)
                .page(InternalPage.class).uri("internal");

        // secured context
        inContext("admin")
                .page(DashboardPage.class).asHomePage()
                .page(UsersPage.class).uri("users");

        // different theme context
    }

    public static DemoNavigationConfig getInstance() {
        // WARN: be aware that this implementation is not thread safe (two concurrent calls will lead to two configuration instances)!
        // use correct singleton implementation in your application
        if (demoNavigationConfig == null) {
            demoNavigationConfig = new DemoNavigationConfig();
        }
        return demoNavigationConfig;
    }
}
